package com.thrsdk.utils;


import android.os.Handler;
import android.os.Looper;

/**
 * @Description: 管理线程的工具类
 * @Author: Xiang Kejia
 * @Date: 2022/6/2 14:26
 */
public class ThreadUtils {
    private static final Handler mMainHandler = new Handler(Looper.getMainLooper());

    /**
     * 主线程运行
     * @param runnable 需要运行的代码块
     */
    public static void runOnUiThread(Runnable runnable) {
        mMainHandler.post(runnable);
    }

    /**
     * 主线程延迟执行
     */
    public static void postDelayed(Runnable runnable, long delayMillis) {
        mMainHandler.postDelayed(runnable, delayMillis);
    }

    /**
     * 清空某个任务
     */
    public static void removeTask(Runnable runnable){
        mMainHandler.removeCallbacks(runnable);
    }

    /**
     * 清空当前所有任务
     */
    public static void removeAllTask(){
        mMainHandler.removeCallbacksAndMessages(null);
    }
}
